/* Constructor */
BelMenu = {}

/* Initialization */
BelMenu.Initialize					= function( self, ... )

	/* Base stuff */
	BelFrame.Initialize( self, ... )
	
	/* Default values */
	self.Items						= {}
	self.LinkedObject				= nil
	
end

/* Add an item */
BelMenu.AddItem						= function( self, text, target )

	/* Ensure menu item values */
	if not IsString( text ) then
		text						= tostring( text )
	end
	if target and not IsFunction( target ) and not IsValidInstance( target, BelMenu ) and not IsValidInstance( target, BelMenuContents ) then
		DEBUG:ErrMsg( "The target parameter must be a valid function or BelMenu or BelMenuContents", "BelMenu.AddItem" )
		return
	end
	
	/* Create a new menu item & add it to the control */
	item							= vgui.Create( "BelMenuItem", self )
	item:SetText( text )
	item:Initialize( self, target )
	item.OnCheckedChanged = self.ItemCheckedChanged
	BelControls.AddHook( "OnPointed", item, self.ItemPointed )
	
	/* Add it to the list */
	table.insert( self.Items, item )
	
	/* If it is the first item, follow it */
	-- if table.Count( self.Items ) == 1 then
		-- self.ItemFollower:GoTo(item)
	-- end
end

/* When an item is checked or unchecked */
BelMenu.ItemCheckedChanged			= function( item, value )
	
	/* Retrieve the menu */
	local self						= item.ParentMenu
	
	/* Remember the selected item */
	if value then
		self.SelectedItem			= item
	end
	
	/* If the item was checked, uncheck others */
	if util.tobool( value ) then
		for _,v in pairs( item.ParentMenu.Items ) do
			if v != item then
				v:SetChecked(false)
			end
		end
	end
end

/* When an item is pointed */
BelMenu.ItemPointed					= function( item )

	/* Notify the item followed to go to that item */
	-- item.ParentMenu.ItemFollower:GoTo(item)
end

/* Register the control */
vgui.Register( "BelMenu", BelMenu, "BelFrame" )